home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
COMMANDS
/
LSR.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
10KB
|
419 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 012290 : Initial
*
* lsr - list resource
*/
#include <ResourceMgr.h>
#include "SystemPub.h"
#include "Proc.h"
#include "ShellPub.h"
#include "Path.h"
/*******************************************************************
*
* Function LSR
*
* PathName Callback function
*
* usage LSR [options] [names]
*
*
*******************************************************************/
extern char resName[], resAttrStr[];
#define lsrResType (**MyShell).Proc[ProcID].long0
#define lsrSize (**MyShell).Proc[ProcID].long1
#define lsrIDStart (**MyShell).Proc[ProcID].int0
#define lsrIDEnd (**MyShell).Proc[ProcID].int1
#define checkT (**MyShell).Proc[ProcID].int2
#define lsrTypes (**MyShell).Proc[ProcID].bflags.f0
#define lsrIDs (**MyShell).Proc[ProcID].bflags.f1
#define lsrData (**MyShell).Proc[ProcID].bflags.f2
#define lsrAbort (**MyShell).Proc[ProcID].bflags.f3
GetResAttrString( Handle resHand )
{
int16 resAttr, i = 0;
resAttr = GetResAttrs( resHand );
resAttrStr[ i++ ] = (resAttr & resSysRef ? 'S' : 's');
resAttrStr[ i++ ] = (resAttr & resSysHeap ? 'H' : 'h');
resAttrStr[ i++ ] = (resAttr & resPurgeable ? 'U' : 'u');
resAttrStr[ i++ ] = (resAttr & resLocked ? 'L' : 'l');
resAttrStr[ i++ ] = (resAttr & resProtected ? 'R' : 'r');
resAttrStr[ i++ ] = (resAttr & resPreload ? 'P' : 'p');
resAttrStr[ i++ ] = (resAttr & resChanged ? 'C' : 'c');
resAttrStr[ i ] = '\0';
}
/*******************************************************************/
void lsrDumpType( WHandle ShellWh, int16 ProcID, OsType theType,
int16 numRes )
{
OsType aType;
Boolean dropOut = FALSE;
int16 resID;
Handle h;
char str[ 64 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
while( --numRes && !dropOut && !UserAbort() )
{
h = Get1IndResource( theType, numRes );
if( h )
{
GetResInfo( h, &resID, &aType, str );
if( checkT == 2 )
{
if( resID < lsrIDStart )
continue;
else if( resID > lsrIDEnd )
continue;
}
else if( checkT == 1 )
if( resID != lsrIDStart )
continue;
GetResAttrString( h );
lsrSize = SizeResource( h );
procPrintf( ShellWh, ProcID, " %2d : %6d %s %6ld %ps\n",
numRes, resID, resAttrStr, lsrSize, str );
}
if( UserAbort() )
dropOut = TRUE;
}
}
/*******************************************************************/
void lsrDumpName( WHandle ShellWh, int16 ProcID,
OsType theType, char *theName )
{
OsType aType;
Handle h;
char str[ 64 ];
int16 resID;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
strcpy( str, theName );
CtoPstr( str );
h = Get1NamedResource( theType, str );
if( h )
{
GetResInfo( h, &resID, &aType, str );
if( checkT == 2 )
{
if( resID < lsrIDStart )
return;
else if( resID > lsrIDEnd )
return;
}
else if( checkT == 1 )
if( resID != lsrIDStart )
return;
GetResAttrString( h );
lsrSize = SizeResource( h );
procPrintf( ShellWh, ProcID, " : %6d %s %6ld %ps\n",
resID, resAttrStr, lsrSize, str );
}
}
/*******************************************************************/
void LSRCallBack( WHandle ShellWh, int16 ProcID, char *path,
char *last, pathType what, int16 vRefNum, int32 dirID )
{
char str[ 256 ];
OSErr err;
int16 refNum, currFile, numTypes, numRes, resID, resFileWasOpen = FALSE;
OsType theType, aType;
Handle h;
Boolean dropOut = FALSE, fileName = TRUE;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
if( what == pathIsFile )
{
strcpy( str, last );
CtoPstr( str );
err = HSetVol( NULL, vRefNum, dirID );
if( err )
return;
currFile = CurResFile();
if( ResFileOpen( last, vRefNum, dirID, &refNum ) )
resFileWasOpen = TRUE;
else
refNum = OpenResFile( str );
if( refNum != (-1) )
{
UseResFile( refNum );
SetResLoad( FALSE );
numTypes = Count1Types() + 1;
while( --numTypes && !dropOut && !lsrAbort )
{
if( UserAbort() )
lsrAbort = TRUE;
Get1IndType( &theType, numTypes ); /* What type is this ? */
TypeToStr( theType, str );
numRes = Count1Resources( theType ) + 1;
if( lsrResType && (lsrResType != theType ) )
continue;
if( fileName )
{
procPrintf( ShellWh, ProcID, "lsr : %s\n", last );
fileName = FALSE;
}
procPrintf( ShellWh, ProcID,
" %s (%d)\n", str, numRes - 1 );
procPrintf( ShellWh, ProcID,
" -- Index --- ID - Flags - Size -- Name ------\n" );
if( *resName )
lsrDumpName( ShellWh, ProcID, theType, resName );
else
lsrDumpType( ShellWh, ProcID, theType, numRes );
}
if( !resFileWasOpen )
CloseResFile( refNum );
SetResLoad( TRUE );
UseResFile( currFile );
}
else if( (err = ResError()) && (err != eofErr) )
procPrintf( ShellWh, ProcID, "lsr : error openning file %s (%d)\n",
last, err );
}
}
/*******************************************************************/
void LSRFile( WHandle ShellWh, int16 ProcID, char *argument )
{
ShellWindRec **MyShell;
MyShell = (ShellWindRec **) (**ShellWh).thing;
ExpandPath( ShellWh, ProcID, argument, (ProcPtr) LSRCallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
ResetShellPWD( ShellWh );
}
/*******************************************************************/
Boolean DoLSR( int16 ProcToken, WHandle ShellWh, int16 ProcID,
char *string )
{
int16 i, argc;
char *cp, argument[ 256 ], badIDs = FALSE;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
lsrAbort = TRUE;
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
/* get arguments */
argc = (**MyShell).Proc[ ProcID ].argc;
lsrTypes = TRUE;
lsrIDs = TRUE;
lsrData = TRUE;
checkT = 0;
lsrIDStart = 0;
lsrIDEnd = 0;
lsrResType = 0L; /* no type specifier */
lsrAbort = FALSE;
*resName = '\0';
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 'n' : /* Name */
i++;
GetArgv( ShellWh, ProcID, i, resName );
break;
case 'i' : /* id's */
i++;
if( i < argc )
{
char *cp, nc, temp[ 64 ], num[ 64 ];
int32 lnum;
GetArgv( ShellWh, ProcID, i, temp );
cp = temp;
while( *cp && (*cp != ',') )
cp++;
nc = *cp;
if( *cp )
*cp = '\0';
CtoPstr( temp );
if( GoodNum( temp ) )
{
StringToNum( temp, &lnum );
lsrIDStart = (int16) lnum;
checkT++;
if( nc )
{
cp++;
CtoPstr( cp );
if( GoodNum( cp ) )
{
StringToNum( cp, &lnum );
lsrIDEnd = (int16) lnum;
checkT++;
}
else
badIDs = TRUE;
}
}
else
badIDs = TRUE;
}
break;
case 't' : /* Type */
i++;
if( i < argc )
{
char temp[ 256 ];
GetArgv( ShellWh, ProcID, i, temp );
lsrResType = StrToType( temp );
}
break;
}
}
if( badIDs )
procPrintf( ShellWh, ProcID, "lsr : bad resource ID\n" );
else
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( *argument != '-' )
LSRFile( ShellWh, ProcID, argument );
else
switch( argument[ 1 ] )
{
case 'n' :
case 'i' :
case 't' :
i++;
break;
}
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}